/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package basics.strings;

/**
 *
 * @author peng
 */
public class StringDemo {
    
    /**
     * Reverse a string
     * @param s
     * @return reverse of s
     */
    public static String reverseStr(String s)
    {
            String ans="";
            int l=s.length();
            for(int i=l-1; i>=0; i--)
            {
                    char tmp=s.charAt(i);
                    ans=ans+tmp;
            }
            return ans;
    }

    public static void main(String args[])
    {
        
        String s1 ="123456789";
        String s2 ="abcdefghijklmn";
        
        //compare 2 strings
        if(s1.equals(s2))
            System.out.println(s1+"="+s2);
        else
            System.out.println(s1+"!="+s2);
        
        //Creating a string using string builder
        StringBuilder s3 = new StringBuilder("");
        s3.append("This ");
        s3.append("is ");
        s3.append("built by StringBuilder!");
        System.out.println(s3);
        
        //Convert the string to an integer
        int a = Integer.parseInt("123");
        System.out.println("Integer: "+a);
        
        //Convert the string to a double
        double b = Double.parseDouble("12.3");
        System.out.println("double: "+b);
        
        
        //Reverse the string s2 and print it
        System.out.println(reverseStr(s2));
        
    }
    
}
